/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.system;

/*
 * Copyright 2009 Prime Technology.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped
public class ThemeSwitcherBean {
        
    private Map<String, String> themes;
    
    private List<Theme> advancedThemes;
    
    private String theme="home";
    
    private GuestPreferences gp;
    

    public ThemeSwitcherBean() {
        
        gp = new GuestPreferences();
     //   init();
    }

    
    
    public void setGp(GuestPreferences gp) {
        this.gp = gp;
    
    }
    
    public Map<String, String> getThemes() {
        return themes;
    }

    public String getTheme() {
        return theme;
    }

    public void setTheme(String theme) {
        this.theme = theme;
    }
    
    public void chooseTheme(){
        FacesContext fc = FacesContext.getCurrentInstance();
        
        String x = fc.getExternalContext().getRequestParameterMap().get("themeChoose");
        this.theme = "cupertino";
        saveTheme();
    }

    @PostConstruct
    public void init() {
        theme = gp.getTheme();
        
        advancedThemes = new ArrayList<>();
    //    advancedThemes.add(new Theme("aristo", "./resources/images/aristo.png","Aristo"));
        advancedThemes.add(new Theme("black-tie", "./resources/images/black-tie.png","Black-Tie"));
        advancedThemes.add(new Theme("blitzer", "./resources/images/blitzer.png","Blitzer"));
        advancedThemes.add(new Theme("bluesky", "./resources/images/bluesky.png","Bluesky"));
        advancedThemes.add(new Theme("casablanca", "./resources/images/casablanca.png","Casablanca"));        
        advancedThemes.add(new Theme("cupertino", "./resources/images/cupertino.png","Cupertino"));
        advancedThemes.add(new Theme("dark-hive", "./resources/images/dark-hive.png","Dark-Hive"));
        advancedThemes.add(new Theme("dot-luv", "./resources/images/dot-luv.png","Dot-Luv"));
        advancedThemes.add(new Theme("eggplant", "./resources/images/eggplant.png","Eggplant"));
        advancedThemes.add(new Theme("excite-bike", "./resources/images/excite-bike.png","Excite-Bike"));
        advancedThemes.add(new Theme("flick", "./resources/images/flick.png","Flick"));
        advancedThemes.add(new Theme("glass-x", "./resources/images/glass-x.png","Glass-X"));
        advancedThemes.add(new Theme("home", "./resources/images/home.png","Home"));
        advancedThemes.add(new Theme("hot-sneaks", "./resources/images/hot-sneaks.png","Hot-Sneaks"));
        advancedThemes.add(new Theme("humanity", "./resources/images/humanity.png","Humanity"));
        advancedThemes.add(new Theme("le-frog", "./resources/images/le-frog.png","Le-Frog"));
        advancedThemes.add(new Theme("midnight", "./resources/images/midnight.png","Midnight"));
        advancedThemes.add(new Theme("mint-choc", "./resources/images/mint-choc.png","Mint-Choc"));
        advancedThemes.add(new Theme("overcast", "./resources/images/overcast.png","Overcast"));
        advancedThemes.add(new Theme("pepper-grinder", "./resources/images/pepper-grinder.png","Pepper-Grinder"));
        advancedThemes.add(new Theme("redmond", "./resources/images/redmond.png","Redmond"));
        advancedThemes.add(new Theme("rocket", "./resources/images/rocket.png","Rocket"));
        advancedThemes.add(new Theme("sam", "./resources/images/sam.png","Sam"));
        advancedThemes.add(new Theme("smoothness", "./resources/images/smoothness.png","Smoothness"));
        advancedThemes.add(new Theme("south-street", "./resources/images/south-street.png","South-Street"));
        advancedThemes.add(new Theme("start", "./resources/images/start.png","Start"));
        advancedThemes.add(new Theme("sunny", "./resources/images/sunny.png","Sunny"));
        advancedThemes.add(new Theme("swanky-purse", "./resources/images/swanky-purse.png","Swanky-Purse"));        
        advancedThemes.add(new Theme("trontastic", "./resources/images/trontastic.png","Trontastic"));
        advancedThemes.add(new Theme("ui-darkness", "./resources/images/ui-darkness.png","UI-Darkness"));
        advancedThemes.add(new Theme("ui-lightness", "./resources/images/ui-lightness.png","UI-Lightness"));
        advancedThemes.add(new Theme("vader", "./resources/images/vader.png","Vader"));
        
        themes = new TreeMap<>();
       // themes.put("Aristo", "aristo");
        themes.put("Black-Tie", "black-tie");
        themes.put("Blitzer", "blitzer");
        themes.put("Bluesky", "bluesky");
        themes.put("Casablanca", "casablanca");
        themes.put("Cupertino", "cupertino");
        themes.put("Dark-Hiave", "dark-hive");
        themes.put("Dot-Luv", "dot-luv");
        themes.put("Eggplant", "eggplant");
        themes.put("Excite-Bike", "excite-bike");
        themes.put("Flick", "flick");
        themes.put("Glass-X", "glass-x");
        themes.put("Home", "home");
        themes.put("Hot-Sneaks", "hot-sneaks");
        themes.put("Humanity", "humanity");
        themes.put("Le-Frog", "le-frog");
        themes.put("Midnight", "midnight");
        themes.put("Mint-Choc", "mint-choc");
        themes.put("Overcast", "overcast");
        themes.put("Pepper-Grinder", "pepper-grinder");
        themes.put("Redmond", "redmond");
        themes.put("Rocket", "rocket");
        themes.put("Sam", "sam");
        themes.put("Smoothness", "smoothness");
        themes.put("South-Street", "south-street");
        themes.put("Start", "start");
        themes.put("Sunny", "sunny");
        themes.put("Swanky-Purse", "swanky-purse");
        themes.put("Trontastic", "trontastic");
        themes.put("UI-Darkness", "ui-darkness");
        themes.put("UI-Lightness", "ui-lightness");
        themes.put("Vader", "vader");
    }
    
    public void saveTheme() {
        gp.setTheme(theme);
    }

    public List<Theme> getAdvancedThemes() {
        return advancedThemes;
    }

    public Theme showCurrentTheme(String name) {
        Theme rs = null;
        for (int i=0;i<advancedThemes.size();i++){
            Theme x = advancedThemes.get(i);
            if (x.getName().equals(name)) {
                rs = x;
                break;
            }
        }
        return rs;
    }
    
    
}
                    